//
//  MessageSettingCell.m
//  AILock
//
//  Created by 谭亚明 on 2020/7/11.
//  Copyright © 2020 tym. All rights reserved.
//

#import "MessageSettingCell.h"
#import "UIView+ZFFrame.h"
#import "UIImageView+YPImage.h"
@interface MessageSettingCell ()

@property(nonatomic,weak) UIImageView *equImage;
@property(nonatomic,weak) TYMLabel*equNameLab;
@property(nonatomic,weak) UISwitch *switchBtn;
@end

@implementation MessageSettingCell


-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self initUI];
    }
    return self;
}

-(void)initUI{
    UIImageView *image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_home3"]];
    image.contentMode = UIViewContentModeScaleAspectFill;
    image.frame = CGRectMake(10,10, 40, 40);
    [self.contentView addSubview:image];
    self.equImage = image;
    
    TYMLabel *titLab = [TYMLabel lb_text:@"大猫眼" font:Font_Medium(15) color:rgba(74, 74, 74)];
    titLab.frame = CGRectMake(self.equImage.zf_right + 10, 20, 150, 20 );
    [self.contentView addSubview:titLab];
    self.equNameLab = titLab;
    
    UISwitch *sithch = [[UISwitch alloc] initWithFrame:CGRectMake(ScreenWidth - 45 - 45, 14.5, 49, 31)];
    
    sithch.onTintColor = rgba(235, 238, 241);
    sithch.tintColor = rgba(235, 238, 241);
    [sithch addTarget:self action:@selector(switchOnAction:) forControlEvents:UIControlEventValueChanged];
    [self.contentView addSubview:sithch];
    self.switchBtn = sithch;
}

//是否能用
-(void)setChangeMessageBtn:(BOOL)isUse{
    if(!isUse){
        self.switchBtn.thumbTintColor = rgba(155, 155, 155);
        self.switchBtn.userInteractionEnabled = NO;
    }else{
        self.switchBtn.userInteractionEnabled = YES;
        [self switchOnAction:self.switchBtn];
    }
}

-(void)switchOnAction:(UISwitch*)sender{
    
    
    if (!sender.on) {
        self.switchBtn.thumbTintColor = rgba(155, 155, 155);
    }else{
        self.switchBtn.thumbTintColor = rgba(76, 132, 255);
    }
    if (self.equmentMessageSettingBlock) {
        self.equmentMessageSettingBlock(sender.on);
    }
}

-(void)setUserModel:(UserMessageModel *)userModel{
    _userModel = userModel;
    _equNameLab.text = userModel.equipmentName;
    [_equImage yp_setImageUlr:[userModel getEquipmentImage]];
    
    [self.switchBtn setOn:userModel.open];
    [self switchOnAction:self.switchBtn];
}

+(NSString*)identifier{
    return @"MessageSettingCell";
}

+(CGFloat)cellForHeight{
    return 60;
}
@end
